﻿using Abp.AspNetCore;
using Abp.AspNetCore.Configuration;
using Abp.Modules;
using Abp.Reflection.Extensions;
using Ny.CenterServers.Configuration;
using Ny.CenterServers.EntityFrameworkCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Ny.Ci.Application;
using Ny.Ci.EntityFrameworkCore.EntityFrameworkCore;

namespace Ny.CenterServers.Web.Startup
{
    [DependsOn(
        typeof(CenterServersApplicationModule),
        typeof(CenterServersEntityFrameworkCoreModule),
        typeof(CiApplicationModule),
        typeof(CiEntityFrameworkCoreModule),
        typeof(AbpAspNetCoreModule))]
    public class CenterServersWebModule : AbpModule
    {
        private readonly IConfigurationRoot _appConfiguration;

        public CenterServersWebModule(IHostingEnvironment env)
        {
            _appConfiguration = AppConfigurations.Get(env.ContentRootPath, env.EnvironmentName);
        }

        public override void PreInitialize()
        {
            //配置数据库路径
            //Configuration.DefaultNameOrConnectionString = _appConfiguration.GetConnectionString(CenterServersConsts.ConnectionStringName);
            Configuration.Navigation.Providers.Add<CenterServersNavigationProvider>();
            
            Configuration.Modules.AbpAspNetCore()
                .CreateControllersForAppServices(
                    typeof(CenterServersApplicationModule).GetAssembly(), "Center"
                );

            Configuration.Modules.AbpAspNetCore()
              .CreateControllersForAppServices(
                  typeof(CiApplicationModule).GetAssembly(), "Ci"
              );
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(CenterServersWebModule).GetAssembly());
        }


    }
}